package rlyy.core.test;

import rlyy.framework.core.common.exception.BusinessException;
import rlyy.framework.core.common.exception.ParameterValidException;
import rlyy.framework.core.common.response.ResponseResult;
import rlyy.framework.core.common.response.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ValidationException;

@Slf4j
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(ValidationException.class)
    public ResponseResult handleMethodArgumentNotValidException(ValidationException e) {
        log.error(e.getMessage(), e);
        return ResultUtil.error(new BusinessException(e));
    }

    @ExceptionHandler(ParameterValidException.class)
    public ResponseResult handleMethodArgumentNotValidException(ParameterValidException e) {
        log.error(e.getMessage(), e);
        return ResultUtil.error(e);
    }

}
